  # encoding: utf-8

class Security::Person < ActiveRecord::Base
  has_many :obj_complaint, :class_name => 'RequestAndComplaint::Complaint', :foreign_key => 'complaint'
  has_many :obj_collection, :class_name => 'CulturalHeritage::Collection',  :foreign_key => 'owner'

  #has_many :obj_care_and_maintenance, :class_name => 'CulturalHeritage::CareAndMaintenance',  :foreign_key => 'responsible'
  
  #has_many :obj_care_and_maintenance_sup, :class_name => 'CulturalHeritage::CareAndMaintenance',  :foreign_key => 'supervisor'
  belongs_to :obj_user, :class_name => 'CulturalHeritage::Collection',  :foreign_key => 'owner'
  default_scope where("deleted = 0")

  validates :name, :presence => {:message => "El nombre es requerido"}
  validates :lastname, :presence => {:message => "Los apellidos son requeridos"}
  #validates :address, :presence => {:message => "La dirección es requerida"}

  def erasable
    care_req = CulturalHeritage::CareAndMaintenance.count_person_dependencies(id)
    collection = CulturalHeritage::Collection.count_person_dependencies(id)
    cultu = CulturalHeritage::CulturalHeritage.count_person_dependencies(id)
    inci = CulturalHeritage::Incidence.count_person_dependencies(id)
    if care_req >0
      return "Imposible borrar. Existen dependencias en cuidado y mantenimiento"    
    end
    if collection >0
      return "Imposible borrar. Existen dependencias en coleccion"    
    end
    if cultu >0
      return "Imposible borrar. Existen dependencias en cultura"    
    end
    if inci >0
      return "Imposible borrar. Existen dependencias en incidencia"    
    end
    return nil
  end

end
